package com.pactera.jep.service.sys.util;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import com.pactera.jep.service.sys.service.SyncService;

/**
 * 同步ESB数据任务类，只有在sync.enabled为true的时候才会被调度
 * 
 * @author ghost
 *
 */
@Component
@ConditionalOnProperty("sync.enabled")
public class SyncTask {

	private final static Logger logger = LoggerFactory.getLogger(SyncTask.class);

	@Autowired
	private SyncService syncService;

	@Scheduled(cron = "${sync.cron}")
	public void sync() {
		try {
			syncService.doSync();
		} catch (Exception e) {
			logger.error("执行同步任务时出现异常：{}", e.getMessage());
		}
	}
}
